<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!-- 静态资源文件 -->
<%@ include file="../head.jsp"%>
<title>用户管理</title>
<style>
.div-top{
	margin-top:10px;
}
</style>
</head>
<script type="text/javascript">
/*绑定网格*/
function funcBindGrid(){
	 var fkey = $("#fkey").val().trim();
	ZD.ux.BindGrid({
		data:{currpage:1,'count':'10',Key:fkey, method:'finance.sys.user.findUserList'},
		table:"dvlist"
	});
}
/*增加用户*/
 function func_add(){
	    $("#myModalLabel").text("新增");
		$("#myModal").modal("show");
		$("#saveBtn").show();
		$("#myModal").find("input").attr("readOnly",false); //不可编辑，可以传值
		$("#myModal").find("select").removeAttr("disabled"); 
		ZD.ux.ClearInputValue("#myModal");
	}
	
/*修改用户*/
function func_update(){
	if(ZD.ux.SelectedCheckboxCount("table_info") != 1){
		ZD.msg.alert("请选择一条记录进行操作.");
		return;
	}
	var fid = ZD.ux.SelectedCheckboxIds("table_info");
	$("#myModalLabel").text("修改");
	ZD.ux.Ajax({
		data:{user_id:fid,method:'finance.sys.user.get'},
		success:function(res){
			if(res.status == 0){
				ZD.ux.InitInputValue(res.data);
				$("#password_tem").val(res.data.password);
				$("#myModal").find("input").attr("readOnly",false); //不可编辑，可以传值
				$("#myModal").find("select").removeAttr("disabled"); 
				$("#myModal").modal("show");
			}
		}
	});
	
	$("#myModal").modal("show");
	$("#saveBtn").show();
}

/*禁用或者启用用户*/
function func_disable(){
	if(ZD.ux.SelectedCheckboxCount("table_info") != 1){
		ZD.msg.alert("请选择一条记录进行操作.");
		return;
	}
	var fid = ZD.ux.SelectedCheckboxIds("table_info");
	ZD.msg.confirm("您确定要启用或禁用勾选的["+ZD.ux.SelectedCheckboxCount("table_info")+"]条记录吗？",function(){
		ZD.ux.Ajax({
			data:{id:fid,method:'finance.sys.user.disableUser'},
			success:function(res){
				if(res.status == 0){
					funcBindGrid();
				}else{
					ZD.msg.alert("操作失败:"+res.msg);
				}
			}
		});
	});
}

/*删除用户*/
function func_delete(){
	if(ZD.ux.SelectedCheckboxCount("table_info") != 1){
		ZD.msg.alert("请选择一条记录进行操作.");
		return;
	}
	var fid = ZD.ux.SelectedCheckboxIds("table_info");
	ZD.msg.confirm("您确定要删除勾选的["+ZD.ux.SelectedCheckboxCount("table_info")+"]条记录吗？",function(){
		ZD.ux.Ajax({
			data:{id:fid,method:'finance.sys.user.deleteUser'},
			success:function(res){
				if(res.status == 0){
					funcBindGrid();
				}else{
					ZD.msg.alert("操作失败:"+res.msg);
				}
			}
		});
	});
}
	
 /*保存记录*/
function func_save(){
		/*正则验证*/
		if(!ZD.ux.Verify()){
			return false;
		}	
		/*遍历标签下的所有input标签*/
		var fdata = ZD.ux.GetInputValue("#myModal");
		if(fdata.id.length > 0){
			fdata.method = 'finance.sys.user.update';
		}else{
			fdata.method = 'finance.sys.user.add';
		}
		
		/*新增或编辑*/
		ZD.ux.Ajax({
			data:fdata,
			success:function(res){
				if(res.status == 0){
					$("#myModal").modal("hide");
					funcBindGrid();
				}else{
					ZD.msg.alert("操作失败:"+res.msg);
				}
			}
		});
	}
 
/*查看*/
function func_read(){
	if(ZD.ux.SelectedCheckboxCount("table_info") != 1){
		ZD.msg.alert("请选择一条记录进行操作.");
		return;
	}
	var fid = ZD.ux.SelectedCheckboxIds("table_info");
	$("#myModalLabel").text("查看");
	ZD.ux.Ajax({
		data:{user_id:fid,method:'finance.sys.user.get'},
		success:function(res){
			if(res.status == 0){
				ZD.ux.InitInputValue(res.data);
				$("#password_tem").val(res.data.password);
				console.log('readOnly');
				$("#myModal").modal("show");
				$("#myModal").find("input").attr("readOnly",true); //不可编辑，可以传值
				$("#myModal").find("select").attr("disabled","disabled"); 
			}
		}
	});
	
	$("#myModal").modal("show");
	$("#saveBtn").hide();
}

$(function(){
	/*绑定数据*/
	funcBindGrid();
	
	/*角色下拉框*/
	ZD.ux.InitSelect({
		select:"role_id",
		data:{currpage:1,count:100,method:'finance.sys.role.findRoleList'}
	});
});
</script>
<body>
	<div class="panel panel-primary">
		<div class="panel-heading">用户管理</div>
		<div class="panel-body">
			<!-- 搜索面板 -->
			<div style="width: 200px;">
				<div class="input-group">
					<input type="text" class="form-control" id="fkey">
					<span class="input-group-btn">
						<button class="btn btn-default" type="button" onclick="funcBindGrid();">搜索</button>
					</span>
				</div>
			</div>

			<!-- 按钮组 -->
			<div class="btn-toolbar div-top">
				<div class="btn-group">
					<button class="btn" onclick="func_read();">
						<i class="icon icon-file-text-o">查看</i>
					</button>
				</div>
				<div class="btn-group">
					<button class="btn" onclick="func_update();">
						<i class="icon icon-save" >修改</i>
					</button>
				</div>

				<div class="btn-group">
					<button class="btn" class="btn btn-lg btn-primary" onclick="func_add();" >
						<i class="icon icon-plus">增加</i>
					</button>
				</div>
				<div class="btn-group">
					<button class="btn" onclick="func_disable();">
						<i class="icon icon-lock" >禁用</i>
					</button>
				</div>
				<div class="btn-group">
					<button class="btn" onclick="func_delete();">
						<i class="icon icon-minus">删除</i>
					</button>
				</div>
			</div>

			<!--表格控件 -->
			<table  class="table table-hover div-top" id="table_info">
				<thead>
					<tr>
						<th>#</th>
						<th>登录账号</th>
						<th>姓名</th>
						<th>角色</th>
						<th>上次登录时间</th>
						<th>状态</th>
					</tr>
				</thead>
				<tbody id="dvlist">
					<tr>
						<td class="center" style="width: 50px;">
							<label><input type='checkbox' name='ids' value="{{id}}" alt="{{id}}"/><span class="lbl"></span></label>
						</td>
						<td>{{username}}</td>
						<td>{{name}}</td>
						<td>{{roleName}}</td>
						<td>{{login_time}}</td>
						<td>{{statusName}}</td>
					</tr>
				</tbody>
			</table>

		</div>
	</div>

<!-- ...编辑的弹框... -->
	<div class="modal fade" id="myModal" tabindex="-1" User="dialog" aria-labelledby="myModalLabel">
	  <div class="modal-dialog" User="document">
	   <div class="modal-content">
	    <div class="modal-header">
	     <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
	     <h4 class="modal-title" id="myModalLabel">{title}</h4>
	    </div>
	    <div class="modal-body">
	     <input type="hidden" id="id" />
	     <input type="hidden" id="password_tem" />
	      <div class="form-group">
	      <label for="txt_parentdepartment">姓名</label>
	      <input type="text" class="form-control" id="name" placeholder="姓名" data-verify="Empty" data-verify_text="姓名不能为空" >
	     </div>
	     <div class="form-group">
	      <label for="txt_parentdepartment">账户</label>
	      <input type="text" class="form-control" id="username" placeholder="账户" data-verify="Empty" data-verify_text="账户不能为空" >
	     </div>
	     <div class="form-group">
	      <label for="txt_parentdepartment">密码</label>
	      <input type="password" class="form-control" id="password" placeholder="密码" data-verify="Empty" data-verify_text="密码不能为空" >
	     </div>
	     <div class="form-group">
	      <label for="txt_parentdepartment">角色</label>
	      <select id="role_id" class="selectpicker form-control" data-live-search="true" data-verify="Empty" data-verify_text="角色不能为空" >
	      	<option value="{{id}}">{{role_name}}</option>
	      </select>
	     </div>
	     <div class="form-group">
	      <label for="txt_departmentlevel">备注</label>
	      <input type="text" class="form-control" id="remark" placeholder="备注">
	     </div>
	    <div class="modal-footer">
	     <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	     <button type="button" class="btn btn-primary" onclick="func_save();" id="saveBtn" >保存</button>
	    </div>
	   </div>
	  </div>
	 </div>
	</div>

</body>
</html>